﻿package{
	
	
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Menu_Result extends Sprite{
		
		
		
		public function Menu_Result(){
			
			addEventListener(Event.ADDED_TO_STAGE, Init);
			Close.addEventListener(MouseEvent.CLICK, onClickClose);
			PlayAgain.addEventListener(MouseEvent.CLICK, onClickPlayAgain);
			
		}
		
		private function Init(e:Event) {
			Cubes.gotoAndStop(Menu_InGame.cubeKind + 1);
			Clickr.cubeArray[Menu_InGame.cubeKind] = Clickr.cubeArray[Menu_InGame.cubeKind] + 1;
			if (Clickr.cubeArray[Menu_InGame.cubeKind] > 99) {
				Clickr.cubeArray[Menu_InGame.cubeKind] = 99;
			}
			
			if (Clickr.bestScored) {
				Clickr.bestScore = BlockMap.SCORE;
				MC_HighScore1.visible = true;
				MC_HighScore2.visible = true;
				MC_HighScore3.visible = true;
				MC_Score.visible = false;
			}else {
				MC_HighScore1.visible = false;
				MC_HighScore2.visible = false;
				MC_HighScore3.visible = false;
				MC_Score.visible = true;
			}
			
			
			if (Clickr.bestScore > 9999999) {
				Clickr.bestScore = 9999999;
			}
			
			
			MovieClip(root).ClickrLocalData.data.bestScore = Clickr.bestScore;
			MovieClip(root).ClickrLocalData.data.cubeArray = Clickr.cubeArray;
			MovieClip(root).ClickrLocalData.flush();
			
			removeEventListener(Event.ADDED_TO_STAGE, Init);
			
		}
		
		private function onClickClose(e:MouseEvent) {
			
			trace(this, ": onClickClose");
			dispatchEvent(new NavigationEvent(NavigationEvent.CLOSE, "resultOut", this));
			
		}
		
		private function onClickPlayAgain(e:MouseEvent):void {
			trace(this, ": onClickPlayAgain");
			dispatchEvent(new NavigationEvent(NavigationEvent.REPLAY, null, this));
			
			//dispatchEvent(new NavigationEvent(NavigationEvent.CLOSE, "records", this));
			
			
		}
		
	}
	
	
}